package com.juc.concurrency.jucExample.locksupport;

import java.util.concurrent.locks.LockSupport;

/**
 * @author huangweiyue
 * @description LockSupport 挂起和唤醒线程
 * @date Created in 2021-08-01
 */
public class LockSupportExample1 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            System.out.println("child thread begin pack!");
            //调用 park方法，挂起自己。默认情况下没有许可 所以会刮起
            LockSupport.park();
            System.out.println("child thread unpark!");
        });
        //启动子线程
        thread.start();
        //主线程休眠5S 目的是为了让主线程调用unpark方法前让字子线程输出child thread begin pack
        Thread.sleep(5000);
        System.out.println("main threaf begin unpark!");
        //调用unpark方法让thread线程持有许可证，然后park方法返回
        LockSupport.unpark(thread);
    }
}
